extern int main();
extern void SystemInit();
extern void __libc_init_array();
/*
naked 属性 告诉编译器 不生成 压栈汇编 push {r7, lr}等指令

ARM 状态与 Thumb 状态
有些处理器同时支持 ARM 和 Thumb 指令集,通过 BX 或 BLX 指令进行切换,当指令 BX
跳转地址的 LSB 位为 1,表示切换到 Thumb 状态,为 0 则切换到 ARM 状态。

无论是 ARM 还是
Thumb,其指令在存储器中都是边界对齐的（2字节或4字节对齐）,也就是地址的最低位总是
0。 因此,在执行跳转过程中,PC 寄存器中的最低位被舍弃,不起作用。 在 BX
指令的执行过程中,最低位正好被用作状态判断的标志,不会造成存储器访问不对齐的错误。

Cortex-M 系列处理器不支持 ARM 指令,因此也不存在 ARM
状态,所以反汇编中的函数地址最低位都是 1

bin 部分数据含义
0x8000000-0x8000003  ：中断向量表定义 栈顶指针,SRAM最大地址  送  SP
0x8000004-0x8000008  : 存储 reset中断函数地址（_start_func） 送  PC
 */

// reset handle

__attribute__((naked)) void Reset_Handler()
{
	extern unsigned int _sidata, _sdata, _edata, _sbss, _ebss;

	unsigned int *sdata;
	unsigned int *data_atflash;
	// copy data from flash to sram
	sdata = &_sdata;
	data_atflash = &_sidata;
	while (sdata < &_edata)
	{
		*sdata++ = *data_atflash++;
	}

	/*clear bss*/
	sdata = &_sbss;
	while (sdata < &_ebss)
	{
		*sdata++ = 0;
	}
	// SystemInit();
	__libc_init_array();
	main();
}

/***********************中断向量声明******************************* */
//  声明 中断函数 防止编译器报错
#ifndef __WEAK
#define __WEAK __attribute__((weak))
#endif

__WEAK void NMI_Handler() /* -14 NMI Handler */
{
	for (;;)
	{
	}
}

__WEAK void HardFault_Handler() /* -13 Hard Fault Handler */
{
	for (;;)
	{
	}
}

__WEAK void MemManage_Handler() {}	 /* -12 MPU Fault Handler */
__WEAK void BusFault_Handler() {}	 /* -11 Bus Fault Handler */
__WEAK void UsageFault_Handler() {}	 /* -10 Usage Fault Handler */
__WEAK void SecureFault_Handler() {} /*  -9 Secure Fault Handler */
__WEAK void SVC_Handler() {}		 /*  -5 SVCall Handler */
__WEAK void DebugMon_Handler() {}	 /*  -4 Debug Monitor Handler */
__WEAK void PendSV_Handler() {}		 /*  -2 PendSV Handler */
__WEAK void SysTick_Handler() {}	 /*  -1 SysTick Handler */

__WEAK void AON_IRQHandler() {}		  /*   0 Interrupt 0  */
__WEAK void ble_isr() {}			  /*   0 Interrupt 0  */
__WEAK void DMAC2_CH1_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void DMAC2_CH2_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void DMAC2_CH3_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void DMAC2_CH4_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void DMAC2_CH5_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void DMAC2_CH6_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void DMAC2_CH7_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void DMAC2_CH8_IRQHandler() {} /*   0 Interrupt 0  */

__WEAK void PATCH_IRQHandler() {}  /*   0 Interrupt 0  */
__WEAK void dm_isr() {}			   /*   0 Interrupt 0  */
__WEAK void USART4_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void USART5_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void SECU2_IRQHandler() {}  /*   0 Interrupt 0  */
__WEAK void bt_isr() {}			   /*   0 Interrupt 0  */
__WEAK void BTIM3_IRQHandler() {}  /*   0 Interrupt 0  */
__WEAK void BTIM4_IRQHandler() {}  /*   0 Interrupt 0  */
__WEAK void PTC2_IRQHandler() {}   /*   0 Interrupt 0  */
__WEAK void LPTIM3_IRQHandler() {} /*   0 Interrupt 0  */

__WEAK void GPIO2_IRQHandler() {}		/*   0 Interrupt 0  */
__WEAK void HPSYS0_IRQHandler() {}		/*   0 Interrupt 0  */
__WEAK void HPSYS1_IRQHandler() {}		/*   0 Interrupt 0  */
__WEAK void Interrupt23_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt24_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt25_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt26_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt27_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt28_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt29_IRQHandler() {} /*   0 Interrupt 0  */

__WEAK void Interrupt30_IRQHandler() {} /*   0 Interrupt 0  */ 
__WEAK void Interrupt31_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt32_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt33_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt34_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt35_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt36_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt37_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt38_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt39_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt40_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt41_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt42_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt43_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt44_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt45_IRQHandler() {} /*   0 Interrupt 0  */

__WEAK void LPTIM1_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void LPTIM2_IRQHandler() {} /*   0 Interrupt 0  */

__WEAK void PMUC_IRQHandler() {}	  /*   0 Interrupt 0  */
__WEAK void RTC_IRQHandler() {}		  /*   0 Interrupt 0  */
__WEAK void DMAC1_CH1_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void DMAC1_CH2_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void DMAC1_CH3_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void DMAC1_CH4_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void DMAC1_CH5_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void DMAC1_CH6_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void DMAC1_CH7_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void DMAC1_CH8_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void LCPU2HCPU_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void USART1_IRQHandler() {}	  /*   0 Interrupt 0  */

__WEAK void SPI1_IRQHandler() {}  /*   0 Interrupt 0  */
__WEAK void I2C1_IRQHandler() {}  /*   0 Interrupt 0  */
__WEAK void EPIC_IRQHandler() {}  /*   0 Interrupt 0  */
__WEAK void LCDC1_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void I2S1_IRQHandler() {}  /*   0 Interrupt 0  */

__WEAK void GPADC_IRQHandler() {}  /*   0 Interrupt 0  */
__WEAK void EFUSEC_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void AES_IRQHandler() {}	   /*   0 Interrupt 0  */
__WEAK void PTC1_IRQHandler() {}   /*   0 Interrupt 0  */
__WEAK void TRNG_IRQHandler() {}   /*   0 Interrupt 0  */

__WEAK void GPTIM1_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void GPTIM2_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void BTIM1_IRQHandler() {}  /*   0 Interrupt 0  */
__WEAK void BTIM2_IRQHandler() {}  /*   0 Interrupt 0  */
__WEAK void USART2_IRQHandler() {} /*   0 Interrupt 0  */

__WEAK void SPI2_IRQHandler() {}   /*   0 Interrupt 0  */
__WEAK void I2C2_IRQHandler() {}   /*   0 Interrupt 0  */
__WEAK void EXTDMA_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void I2C4_IRQHandler() {}   /*   0 Interrupt 0  */
__WEAK void SDMMC1_IRQHandler() {} /*   0 Interrupt 0  */

__WEAK void Interrupt80_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt81_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void PDM1_IRQHandler() {}		/*   0 Interrupt 0  */
__WEAK void Interrupt83_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void GPIO1_IRQHandler() {}		/*   0 Interrupt 0  */

__WEAK void QSPI1_IRQHandler() {}		/*   0 Interrupt 0  */
__WEAK void QSPI2_IRQHandler() {}		/*   0 Interrupt 0  */
__WEAK void Interrupt87_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void Interrupt88_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void EZIP_IRQHandler() {}		/*   0 Interrupt 0  */

__WEAK void AUDPRC_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void TSEN_IRQHandler() {}   /*   0 Interrupt 0  */
__WEAK void USBC_IRQHandler() {}   /*   0 Interrupt 0  */
__WEAK void I2C3_IRQHandler() {}   /*   0 Interrupt 0  */
__WEAK void ATIM1_IRQHandler() {}  /*   0 Interrupt 0  */

__WEAK void USART3_IRQHandler() {}		/*   0 Interrupt 0  */
__WEAK void AUD_HP_IRQHandler() {}		/*   0 Interrupt 0  */
__WEAK void Interrupt97_IRQHandler() {} /*   0 Interrupt 0  */
__WEAK void SECU1_IRQHandler() {}		/*   0 Interrupt 0  */

/*中断向量表 占用data 区*/
extern unsigned int _end_stack_bottom;
__attribute__((section(".vectors"))) const void *__Vectors[] = {
	(void *)(&_end_stack_bottom), /*ram最大地址*/
	/*reset_handler 单片机复位后从这个地址开始运行 */
	/*cortex M只支持thumb2 指令,机器码最低位强制是1,所以地址会+1 */
	Reset_Handler, NMI_Handler, HardFault_Handler, MemManage_Handler, BusFault_Handler, UsageFault_Handler, SecureFault_Handler, 0, 0, 0,
	SVC_Handler, DebugMon_Handler, 0, PendSV_Handler, SysTick_Handler,

	AON_IRQHandler /* 16:Window Watchdog Timer */
	,
	ble_isr /* 17:LVD through EXTI Line detect */

	,
	DMAC2_CH1_IRQHandler /*   2 Interrupt 2  */
	,
	DMAC2_CH2_IRQHandler /*   3 Interrupt 3  */
	,
	DMAC2_CH3_IRQHandler /*   4 Interrupt 4  */
	,
	DMAC2_CH4_IRQHandler /*   5 Interrupt 5  */
	,
	DMAC2_CH5_IRQHandler /*   6 Interrupt 6  */
	,
	DMAC2_CH6_IRQHandler /*   7 Interrupt 7  */
	,
	DMAC2_CH7_IRQHandler /*   8 Interrupt 8  */
	,
	DMAC2_CH8_IRQHandler /*   9 Interrupt 9  */
	,
	PATCH_IRQHandler /*  10 Interrupt 10 */
	,
	dm_isr /*  11 Interrupt 11 */
	,
	USART4_IRQHandler /*  12 Interrupt 12 */
	,
	USART5_IRQHandler /*  13 Interrupt 13 */
	,
	SECU2_IRQHandler /*  14 Interrupt 14 */
	,
	bt_isr /*  15 Interrupt 15 */
	,
	BTIM3_IRQHandler /*  16 Interrupt 16 */
	,
	BTIM4_IRQHandler /*  17 Interrupt 17 */
	,
	PTC2_IRQHandler /*  18 Interrupt 18 */
	,
	LPTIM3_IRQHandler /*  19 Interrupt 19 */
	,
	GPIO2_IRQHandler /*  20 Interrupt 20 */
	,
	HPSYS0_IRQHandler /*  21 Interrupt 21 */
	,
	HPSYS1_IRQHandler /*  22 Interrupt 22 */
	,
	Interrupt23_IRQHandler /*  23 Interrupt 23 */
	,
	Interrupt24_IRQHandler /*  24 Interrupt 24 */
	,
	Interrupt25_IRQHandler /*  25 Interrupt 25 */
	,
	Interrupt26_IRQHandler /*  26 Interrupt 26 */
	,
	Interrupt27_IRQHandler /*  27 Interrupt 27 */
	,
	Interrupt28_IRQHandler /*  28 Interrupt 28 */
	,
	Interrupt29_IRQHandler /*  29 Interrupt 29 */
	,
	Interrupt30_IRQHandler /*  30 Interrupt 30 */
	,
	Interrupt31_IRQHandler /*  31 Interrupt 31 */
	,
	Interrupt32_IRQHandler /*  32 Interrupt 32 */
	,
	Interrupt33_IRQHandler /*  33 Interrupt 33 */
	,
	Interrupt34_IRQHandler /*  34 Interrupt 34 */
	,
	Interrupt35_IRQHandler /*  35 Interrupt 35 */
	,
	Interrupt36_IRQHandler /*  36 Interrupt 36 */
	,
	Interrupt37_IRQHandler /*  37 Interrupt 37 */
	,
	Interrupt38_IRQHandler /*  38 Interrupt 38 */
	,
	Interrupt39_IRQHandler /*  39 Interrupt 39 */
	,
	Interrupt40_IRQHandler /*  40 Interrupt 40 */
	,
	Interrupt41_IRQHandler /*  41 Interrupt 41 */
	,
	Interrupt42_IRQHandler /*  42 Interrupt 42 */
	,
	Interrupt43_IRQHandler /*  43 Interrupt 43 */
	,
	Interrupt44_IRQHandler /*  44 Interrupt 44 */
	,
	Interrupt45_IRQHandler /*  45 Interrupt 45 */
	,
	LPTIM1_IRQHandler /*  46 Interrupt 46 */
	,
	LPTIM2_IRQHandler /*  47 Interrupt 47 */
	,
	PMUC_IRQHandler /*  48 Interrupt 48 */
	,
	RTC_IRQHandler /*  49 Interrupt 49 */
	,
	DMAC1_CH1_IRQHandler /*  50 Interrupt 50 */
	,
	DMAC1_CH2_IRQHandler /*  51 Interrupt 51 */
	,
	DMAC1_CH3_IRQHandler /*  52 Interrupt 52 */
	,
	DMAC1_CH4_IRQHandler /*  53 Interrupt 53 */
	,
	DMAC1_CH5_IRQHandler /*  54 Interrupt 54 */
	,
	DMAC1_CH6_IRQHandler /*  55 Interrupt 55 */
	,
	DMAC1_CH7_IRQHandler /*  56 Interrupt 56 */
	,
	DMAC1_CH8_IRQHandler /*  57 Interrupt 57 */
	,
	LCPU2HCPU_IRQHandler /*  58 Interrupt 58 */
	,
	USART1_IRQHandler /*  59 Interrupt 59 */
	,
	SPI1_IRQHandler /*  60 Interrupt 60 */
	,
	I2C1_IRQHandler /*  61 Interrupt 61 */
	,
	EPIC_IRQHandler /*  62 Interrupt 62 */
	,
	LCDC1_IRQHandler /*  63 Interrupt 63 */
	,
	I2S1_IRQHandler /*  64 Interrupt 64 */
	,
	GPADC_IRQHandler /*  65 Interrupt 65 */
	,
	EFUSEC_IRQHandler /*  66 Interrupt 66 */
	,
	AES_IRQHandler /*  67 Interrupt 67 */
	,
	PTC1_IRQHandler /*  68 Interrupt 68 */
	,
	TRNG_IRQHandler /*  69 Interrupt 69 */
	,
	GPTIM1_IRQHandler /*  70 Interrupt 70 */
	,
	GPTIM2_IRQHandler /*  71 Interrupt 71 */
	,
	BTIM1_IRQHandler /*  72 Interrupt 72 */
	,
	BTIM2_IRQHandler /*  73 Interrupt 73 */
	,
	USART2_IRQHandler /*  74 Interrupt 74 */
	,
	SPI2_IRQHandler /*  75 Interrupt 75 */
	,
	I2C2_IRQHandler /*  76 Interrupt 76 */
	,
	EXTDMA_IRQHandler /*  77 Interrupt 77 */
	,
	I2C4_IRQHandler /*  78 Interrupt 78 */
	,
	SDMMC1_IRQHandler /*  79 Interrupt 79 */
	,
	Interrupt80_IRQHandler /*  80 Interrupt 80 */
	,
	Interrupt81_IRQHandler /*  81 Interrupt 81 */
	,
	PDM1_IRQHandler /*  82 Interrupt 82 */
	,
	Interrupt83_IRQHandler /*  83 Interrupt 83 */
	,
	GPIO1_IRQHandler /*  84 Interrupt 84 */
	,
	QSPI1_IRQHandler /*  85 Interrupt 85 */
	,
	QSPI2_IRQHandler /*  86 Interrupt 86 */
	,
	Interrupt87_IRQHandler /*  87 Interrupt 87 */
	,
	Interrupt88_IRQHandler /*  88 Interrupt 88 */
	,
	EZIP_IRQHandler /*  89 Interrupt 89 */
	,
	AUDPRC_IRQHandler /*  90 Interrupt 90 */
	,
	TSEN_IRQHandler /*  91 Interrupt 91 */
	,
	USBC_IRQHandler /*  92 Interrupt 92 */
	,
	I2C3_IRQHandler /*  93 Interrupt 93 */
	,
	ATIM1_IRQHandler /*  94 Interrupt 94 */
	,
	USART3_IRQHandler /*  95 Interrupt 95 */
	,
	AUD_HP_IRQHandler /*  96 Interrupt 96 */
	,
	Interrupt97_IRQHandler /*  97 Interrupt 97 */
	,
	SECU1_IRQHandler /*  98 Interrupt 98 */
};
